<?php
//============================================================+
// File name   : example_011.php
// Begin       : 2008-03-04
// Last Update : 2010-08-08
//
// Description : Example 011 for TCPDF class
//               Colored Table
//
// Author: Nicola Asuni
//
// (c) Copyright:
//               Nicola Asuni
//               Tecnick.com s.r.l.
//               Via Della Pace, 11
//               09044 Quartucciu (CA)
//               ITALY
//               www.tecnick.com
//               info@tecnick.com
//============================================================+

/**
 * Creates an example PDF TEST document using TCPDF
 * @package com.tecnick.tcpdf
 * @abstract TCPDF - Example: Colored Table
 * @author Nicola Asuni
 * @copyright 2004-2009 Nicola Asuni - Tecnick.com S.r.l (www.tecnick.com) Via Della Pace, 11 - 09044 - Quartucciu (CA) - ITALY - www.tecnick.com - info@tecnick.com
 * @link http://tcpdf.org
 * @license http://www.gnu.org/copyleft/lesser.html LGPL
	* @since 2008-03-04
 */
session_start();
require_once('tcpdf/config/lang/ger.php');
require_once('tcpdf/tcpdf.php');
require ('konfiguration.html');
$custid = isset($_REQUEST['custid']) ? $_REQUEST['custid'] : "";
$langpair = isset($_REQUEST['langpair']) ? $_REQUEST['langpair'] : "";
$rest = isset($_REQUEST['rest']) ? $_REQUEST['rest'] : 0;


// extend TCPF with custom functions
class MYPDF extends TCPDF {

    // Load table data from file
    public function LoadData() {
		
		global $custid,$langpair,$rest;

	
		mysql_query('SET NAMES utf8');
		mysql_query('SET CHARACTER SET utf8');
		$sql = "select 1word, 2word, 3word, word1, word2, word3 from wordbox0 where customerid = ". $custid . " and langpairid =". $langpair . " and boxid =  ". $_SESSION['actbox']  . " order by timestamp LIMIT ". $rest;
		$db_res = mysql_query( $sql );
		if ( ! $db_res ) { die('Error query1: ' . mysql_error()); }
		$value = array();
		$data = array();
		$i=0;
		while ($row = mysql_fetch_array( $db_res, MYSQL_ASSOC)) {
		
		$row0 = isset($row['1word']) ? $row['1word'] : '-';
		$row1 = isset($row['2word']) ? $row['2word'] : '-';
		$row2 = isset($row['3word']) ? $row['3word'] : '-';
		$row3 = isset($row['word1']) ? $row['word1'] : '-';
		$row4 = isset($row['word2']) ? $row['word2'] : '-';
		$row5 = isset($row['word3']) ? $row['word3'] : '-';

		$value[0] = $row0;
		$value[1] = $row1;
		$value[2] = $row2;
		$value[3] = $row3;
		$value[4] = $row4;
		$value[5] = $row5;

		$data[$i] = $value;
		$i=$i+1;
	// Read file lines
    //    $lines = file($file);
    //    $data = array();
    //    foreach($lines as $line) {
    //        $data[] = explode(';', chop($line));
        }
        return $data;
    }

    // Colored table
    public function ColoredTable($header,$data) {
        // Colors, line width and bold font
        $this->SetFillColor(242, 25, 34);
        $this->SetTextColor(255);
        $this->SetDrawColor(90, 90, 90);
        $this->SetLineWidth(0.3);
        $this->SetFont('', 'B');
        // Header
        $w = array(30, 30, 30, 30, 30, 30);
        $num_headers = count($header);
        for($i = 0; $i < $num_headers; ++$i) {
            $this->Cell($w[$i], 7, $header[$i], 1, 0, 'C', 1);
        }
        $this->Ln();
        // Color and font restoration
        $this->SetFillColor(224, 235, 255);
        $this->SetTextColor(0);
        $this->SetFont('');
        // Data
        $fill = 0;
        foreach($data as $row) {
            $this->Cell($w[0], 6, $row[0], 'LR', 0, 'L', $fill);
            $this->Cell($w[1], 6, $row[1], 'LR', 0, 'L', $fill);
            $this->Cell($w[2], 6, $row[2], 'LR', 0, 'L', $fill);
            $this->Cell($w[3], 6, $row[3], 'LR', 0, 'L', $fill);
            $this->Cell($w[4], 6, $row[4], 'LR', 0, 'L', $fill);
            $this->Cell($w[5], 6, $row[5], 'LR', 0, 'L', $fill);
            $this->Ln();
            $fill=!$fill;
        }
        $this->Cell(array_sum($w), 0, '', 'T');
    }
}

// create new PDF document
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Lingomoto');
$pdf->SetTitle('Actual Learn-Box');
$pdf->SetSubject('Fecha ..');
$pdf->SetKeywords('TCPDF2, PDF, example2, test, guide');

// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.'', PDF_HEADER_STRING);

// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

//setting protection... (this is just for not copying words and translations)
$pdf->SetProtection($permissions=array('print', 'copy'), $user_pass='', $owner_pass=null, $mode=0, $pubkeys=null);

//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

//set some language-dependent strings
$pdf->setLanguageArray($l);

// ---------------------------------------------------------
$pdf->setFontSubsetting(false);
// set font
 $pdf->SetFont('freesans', '', 10);
//$pdf->SetFont('dejavusans', '', 12);
// add a page
$pdf->AddPage();

//Column titles
$header = array('Ausgangswort 1', 'Ausgangswort 2', 'Ausgangswort 3', 'Übersetzung 1', 'Übersetzung 2', 'Übersetzung 3');

//Data loading
//$data = $pdf->LoadData();
$data = $pdf->LoadData();
//print_r ($data);
// print colored table
$pdf->ColoredTable($header, $data);

// ---------------------------------------------------------

//Close and output PDF document
$pdf->Output('lingomoto.pdf', 'I');

//============================================================+
// END OF FILE       
// Array ( [0] => Array ( [0] => Austria2 [1] => Vienna [2] => 83859 [3] => 8075 [4] => 3 [5] => 4 ) [1] => Array ( [0] => Belgium [1] => Brussels [2] => 30518 [3] => 10192 [4] => 3 [5] => 4 ) [2] => Array ( [0] => Denmark [1] => Copenhagen [2] => 43094 [3] => 5295 [4] => 3 [5] => 4 ) [3] => Array ( [0] => Finland [1] => Helsinki [2] => 304529 [3] => 5147 [4] => 3 [5] => 4 ) [4] => Array ( [0] => France [1] => Paris [2] => 543965 [3] => 58728 [4] => 3 [5] => 4 ) [5] => Array ( [0] => Germany [1] => Berlin [2] => 357022 [3] => 82057 [4] => 3 [5] => 4 ) [6] => Array ( [0] => Greece [1] => Athens [2] => 131625 [3] => 10511 [4] => 3 [5] => 4 ) [7] => Array ( [0] => Ireland [1] => Dublin [2] => 70723 [3] => 3694 [4] => 3 [5] => 4 ) [8] => Array ( [0] => Italy [1] => Roma [2] => 301316 [3] => 57563 [4] => 3 [5] => 4 ) [9] => Array ( [0] => Luxembourg [1] => Luxembourg [2] => 2586 [3] => 424 [4] => 3 [5] => 4 ) [10] => Array ( [0] => Netherlands [1] => Amsterdam [2] => 41526 [3] => 15654 [4] => 3 [5] => 4 ) [11] => Array ( [0] => Portugal [1] => Lisbon [2] => 91906 [3] => 9957 [4] => 3 [5] => 4 ) [12] => Array ( [0] => Spain [1] => Madrid [2] => 504790 [3] => 39348 [4] => 3 [5] => 4 ) [13] => Array ( [0] => Sweden [1] => Stockholm [2] => 410934 [3] => 8839 [4] => 3 [5] => 4 ) [14] => Array ( [0] => United Kingdom [1] => London [2] => 243820 [3] => 58862 [4] => 3 [5] => 4 ) )                                          
//============================================================+
?>